package com.leo;

import javafx.application.Application;
import javafx.beans.property.ReadOnlyDoubleProperty;
import javafx.beans.property.ReadOnlyDoubleWrapper;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

/**
 * @ClassName BindingClassDemo
 * @Description
 * @Author wangss
 * @date 2020.05.27 16:53
 * @Version 1.0
 */
public class BindingClassDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {

        SimpleIntegerProperty sip = new SimpleIntegerProperty(5);
        System.out.println(sip.get());

        sip.addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                System.out.println("old = " + oldValue);
                System.out.println("new = " + newValue);
            }
        });

        sip.set(10);

        ReadOnlyDoubleWrapper rodw = new ReadOnlyDoubleWrapper(3);
        ReadOnlyDoubleProperty rdp = rodw.getReadOnlyProperty();

        System.out.println(rodw.get());
        rodw.set(10);

        System.out.println(rodw.get());

        AnchorPane anchorPane = new AnchorPane();
        anchorPane.setStyle("-fx-background-color: #e7eeea");
        Scene scene = new Scene(anchorPane);

        primaryStage.setScene(scene);
        primaryStage.setTitle("spinner");
        primaryStage.setWidth(625d);
        primaryStage.setHeight(500d);
        primaryStage.setResizable(false);
        primaryStage.show();
    }
}
